/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package A1;


import java.util.Random;

/**
 *
 * @author Mary Llenos
 * Car class contains the random position of a car in the horizontal
 * and vertical streets
 */
public class Car {

    private int rPos;
    private int cPos;
    private int moveHC;
    private int moveVC;
    private ProjModel project;

    /**
     * Default constructor of Car
     * used to instantiate a ProjModel object
     */
    public Car(){
        project = new ProjModel();    
    }

    /**
     * Sets the random (row, col) position of first car in the horizontal street
     *
     * @param number of horizontal lane
     */
    public void setHorCar(int noHorLane){
        Random rand = new Random();
        int gs = project.getGridSize();
        int middle = 0;
        if (noHorLane == 1 || noHorLane ==2) middle = gs / 2;
        if (noHorLane == 3) middle = (gs/2)-2;
        rPos = rand.nextInt(noHorLane)+middle;
        cPos = rand.nextInt(gs/2);
        moveHC = cPos+1; //to prepare the car for moving forward
    }

    /**
     * Sets the random (row, col) position of incoming car in the horizontal street
     * starts at the left most part of the grid but with random lane position
     *
     * @param number of horizontal lane
     */
    public void setNextHorCar(int noHorLane){
        Random rand = new Random();
        int gs = project.getGridSize();
        int middle = 0;
        if (noHorLane == 1 || noHorLane ==2) middle = gs / 2;
        if (noHorLane == 3) middle = (gs/2)-2;
        rPos = rand.nextInt(noHorLane)+middle;
        cPos = 0;
        moveHC = cPos+1;
    }

    /**
     * Returns row position of car 
     *
     * @return int
     */
    public int getRPos(){
        return rPos;
    }

    /**
     * Returns column position of car 
     *
     * @return int
     */
    public int getCPos(){
        return cPos;
    }

    /**
     * Sets the random (row, col) position of first car in the vertical street
     *
     * @param number of vertical lane
     */
    public void setVerCar(int noVerLane){
        Random rand = new Random();
        int gs = project.getGridSize();
        int middle = 0;
        if (noVerLane == 1 || noVerLane ==2) middle = gs / 2;
        if (noVerLane == 3) middle = (gs/2)-1;
        if (noVerLane ==4) middle = (gs/2)-2;
        cPos = rand.nextInt(noVerLane)+middle;
        rPos = rand.nextInt(gs);
        moveVC = rPos -1;
    }

     /**
     * Sets the random (row, col) position of incoming car in the vertical street
     * starts at the lower most part of the grid but with random lane position
     *
     * @param number of vertical lane
     */
     public void setNextVerCar(int noVerLane){
        Random rand = new Random();
        int gs = project.getGridSize();
        int middle = 0;
        if (noVerLane == 1 || noVerLane ==2) middle = gs / 2;
        if (noVerLane == 3) middle = (gs/2)-1;
        if (noVerLane ==4) middle = (gs/2)-2;
        cPos = rand.nextInt(noVerLane)+middle;
        rPos = gs-1;
        moveVC = rPos -1;
     }

    /**
     * Returns new column position of car in the horizontal street
     *
     * @return int
     */
    public int moveHCar(){
        return moveHC++;
    }

    /**
     * Returns current column position of car in the horizontal street
     *
     * @return int
     */
    public int getMoveHCar(){
        return moveHC;
    }

    /**
     * Sets new row position of car in the horizontal lane to change lane
     *
     * @param row
     */
    public void changeLaneHCar(int row){
        rPos = row;
    }

    /**
     * Returns new row position of car in the vertical street
     *
     * @return int
     */
    public int moveVCar(){
        return moveVC--;
    }

    /**
     * Returns current row position of car in the vertical street
     *
     * @return int
     */
    public int getMoveVCar(){
        return moveVC;
    }

     /**
     * Sets new column position of car in the vertical street to change lane
     *
     * @param row
     */
    public void changeLaneVCar(int col){
        cPos = col;
    }

    /**
     * Returns previous column position of car in the horizontal street
     *
     * @return int
     */
    public int stopHCar(){
        return moveHC--;
    }

    /**
     * Returns previous row position of car in the vertical street
     *
     * @return int
     */
    public int stopVCar(){
        return moveVC++;
    }
}
